package com.fish.admin.module.system.controller;

import com.fish.admin.module.system.domain.dto.SysUserDTO;
import com.fish.admin.module.system.domain.dto.SysUserPageQueryDTO;
import com.fish.admin.module.system.domain.vo.SysUserVO;
import com.fish.admin.module.system.service.SysUserService;
import com.fish.common.core.domain.vo.PageVO;
import com.fish.common.core.response.RestResponse;
import com.fish.common.core.validation.InsertDefaultGroup;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author lindy */
@RequestMapping("/api/user")
@RestController
@RequiredArgsConstructor
@Slf4j
public class SysUserController {

	private final SysUserService sysUserService;

	/**
	 * 新增用户
	 * @param sysUserDTO
	 * @return
	 */
	@PostMapping("/v1/save")
	public RestResponse save(@RequestBody @Validated(InsertDefaultGroup.class) SysUserDTO sysUserDTO) {
		sysUserService.save(sysUserDTO);
		return RestResponse.ok();
	}

	@PostMapping("/v1/delete/{id}")
	public RestResponse deleteById(@PathVariable  Long id) {
		sysUserService.deleteById(id);
		return RestResponse.ok();
	}

	/**
	 * 根据id更新用户
	 * @param id
	 * @param sysUserDTO
	 * @return
	 */
	@PostMapping("/v1/update/{id}")
	public RestResponse updateById(@PathVariable Long id,
								   @RequestBody SysUserDTO sysUserDTO) {
		sysUserService.updateById(id, sysUserDTO);
		return RestResponse.ok();
	}




	/**
	 * 分页获取用户
	 * @param sysUserPageQueryDTO
	 * @return
	 */
	@PostMapping("/v1/page")
	public RestResponse<PageVO<SysUserVO>> page(
			@RequestBody SysUserPageQueryDTO sysUserPageQueryDTO) {
		return RestResponse.ok(sysUserService.page(sysUserPageQueryDTO));
	}

}
